//package com.hmall.pay.mq;
////
////import com.rabbitmq.client.Channel;
////import org.springframework.amqp.core.Message;
////import org.springframework.amqp.rabbit.annotation.*;
////import org.springframework.stereotype.Component;
////
////
////@Component
////public class RabbitMQConfig {
////    /**
////     * 监听消息，绑定队列设置队列过期时间
////     */
////    @RabbitListener(bindings = @QueueBinding(
////            exchange = @Exchange(value = "xkp_topic_exchange",type = "topic"),
////            value = @Queue(
////                    value = "xkp_queue",
////                    durable = "true",
////                    arguments = @Argument( // 设置队列参数
////                            name="x-message-ttl", // 设置队列过期时间
////                            type = "java.lang.Integer",
////                            value = "20000")),
////            key = "xkp.#"
////    ))
////    public void handlerMessage(Message message, Channel channel)throws Exception {
////        long deliveryTag = message.getMessageProperties().getDeliveryTag();
////        // 1. 转换消息
////        System.out.println("消息内容: " + new String(message.getBody()));
////        // 2. 手工签收
////        channel.basicAck(deliveryTag,true);
////    }
////}
//
//import com.rabbitmq.client.Channel;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.Exchange;
//import org.springframework.amqp.rabbit.annotation.Queue;
//import org.springframework.amqp.rabbit.annotation.QueueBinding;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//
//@Component
//public class RabbitMQConfig {
////    @RabbitListener(queues = "dead_xkp_queue")
////    public void listenHotelInsertOrUpdate(Long id) {
////        System.out.println("id = " + id);
////    }
//
//    /**
//     * 测试拒绝签收消息，让消息进入死信队列
//     **/
//    @RabbitListener(bindings = @QueueBinding(
//            exchange = @Exchange(value = "xkp_topic_exchange",type = "topic"),
//            value = @Queue(value = "xkp_queue",durable = "true"),
//            key = "xkp.#"
//    ))
//    public void handlerMessage(Message message, Channel channel)throws IOException {
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        try {
//            // 1. 转换消息
//            System.out.println("消息内容: " + new String(message.getBody()));
//            // 2. 业务处理
//            System.out.println("执行业务处理...");
//            // 模拟异常
//            System.out.println(1/0);
//            // 3. 手工签收
//            channel.basicAck(deliveryTag,true);
//
//        } catch (Exception e) {
//            // 4. 拒绝签收
//            // 参数3：true：重回队列，broker会重新发送该消息给消费端，false：不重回队列，消息会被丢弃或回到死信队列
//            channel.basicNack(deliveryTag,true,false);
//        }
//    }
//
//}